﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.IO;

namespace COFE.Core.Filter
{
    /// <summary>
    /// ILookupFilter that takes a COFE.IO.SearchOptionEx, to return whether continue to lookup a directory.
    /// </summary>
    public class SearchOptionLookupFilter : ILookupFilter
    {
        public SearchOptionLookupFilter(SearchOptionEx searchOption = SearchOptionEx.TopDirectoryOnly)
        {
            _searchOption = searchOption;
        }

        private SearchOptionEx _searchOption;

        public bool ContinueLookup(IInternalDirectoryInfoExA directory)
        {
            switch (_searchOption)
            {
                case SearchOptionEx.TopDirectoryOnly: return false;
                case SearchOptionEx.AllDirectoriesAndFileBasedFS: return true;
                case SearchOptionEx.AllDirectories: return !directory.IsFileBasedFS;
                default: throw new NotImplementedException("SearchOptionEx");
            }            
        }

        public override string ToString()
        {
            return "searchoption=" + _searchOption.ToString();
        }
    }
}
